<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 不设置过期 关闭浏览器后消失
        function setCookie(name,value,day=0) {
            // 过期时间不是必传
            if(day!=0) {
                var expires = day*24* 60 *60*1000;
                var data = new Date(+new Date()+expires);
                // console.log(data.toUTCString())
                document.cookie=`${name}=${escape(value)};expires=${data.toUTCString()}`
            }else {
                document.cookie=`${name}=${escape(value)}`
            }
        }
        setCookie('my','123',1)
    </script>
</body>
</html>